package arabicScrabble;

public class WordOnBoard {
	public String word;
	public int numberOfEmptyCellsBefore;
	public int numberOfEmptyCellsAfter;
	public int i, j;
	public Dictionary dictionary;
	public char direction;

	public WordOnBoard(String word, int i, int j, char direction,
			Dictionary dict, int nCellsBefore, int nCellsAfter) {
		this.word = word;
		this.i = i;
		this.j = j;
		this.direction = direction;
		this.numberOfEmptyCellsAfter = nCellsAfter;
		this.numberOfEmptyCellsBefore = nCellsBefore;
		this.dictionary = dict;
	}

	public boolean addBefore(String str) {
		return str.length() <= numberOfEmptyCellsBefore
				&& dictionary.search(str + word);
	}

	public boolean addAfter(String str) {
		return str.length() <= numberOfEmptyCellsAfter
				&& dictionary.search(word + str);
	}

	public boolean addBeforeAndAfter(String beforeStr, String afterStr) {
		return afterStr.length() <= numberOfEmptyCellsAfter
				&& beforeStr.length() <= numberOfEmptyCellsBefore
				&& dictionary.search(beforeStr + word + afterStr);
	}

	@Override
	public String toString() {

		return this.word;
	}
}

class LetterIndex {
	Letter letter;
	int j;
	int i;

	public LetterIndex(Letter letter, int i, int j) {
		this.letter = letter;
		this.i = i;
		this.j = j;
	}

	public Letter prepare(Square[][] b) {
		if (b[i][j].letter != null) {
			System.err.println("Prepare");
		}
		letter.square = b[i][j];
		b[i][j].letter = letter;
		return letter;
	}

	public Letter clear(Square[][] b) {
		letter.square = null;
		b[i][j].letter = null;
		return letter;
	}

	public Letter play(Square[][] b) {
		letter.square = b[i][j];
		b[i][j].add(letter);
		return letter;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "[Symbol: " + this.letter.symbol + ", i: " + i + ", j: " + j
				+ "]";
	}
}

class validWordOnBoard implements Comparable<validWordOnBoard> {
	public WordOnBoard word;
	public String prefix;
	public String suffix;

	public validWordOnBoard(String prefix, WordOnBoard word, String suffix) {
		this.suffix = suffix;
		this.prefix = prefix;
		this.word = word;
	}

	@Override
	public int compareTo(validWordOnBoard o) {
		return this.getWholeWord().compareTo(o.getWholeWord());
	}

	public String getWholeWord() {
		return this.prefix + this.word + this.suffix;
	}
}